﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Threading;
using System.Globalization;
using MovieCriticsPage;
using MovieCriticsPage.App_GlobalResources;

namespace MovieCriticsPage
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        #region Constants
        private const string c_clientInformationCookie = "L";
        private const string c_defaultCultureName = "en";
        private const string c_languageKey = "Language";
        #endregion

        #region Properties
        private TheApplication _application;

        /// <summary>
        /// 	Gets the <see cref = "TheApplication" /> instance for the current Web request.
        /// </summary>
        /// <value></value>
        /// <remarks>
        /// 	The value is cached after the first value that is not null retrieved from <see cref = "TheApplication.Current" />.
        /// </remarks>
        /// <returns>
        /// 	The <see cref = "TheApplication" /> object for the current Web request.
        /// </returns>
        public new TheApplication Application
        {
            get { return this._application ?? (this._application = TheApplication.Current); }
        }

        public string UICulture { get; set; }
        public string Culture { get; set; }

        #endregion
        protected override void FrameworkInitialize()
        {
            base.FrameworkInitialize();

            string lang = this.Request.Form["ctl00$LanguageChooseBar"];

            if (string.IsNullOrEmpty(lang) == false)
                TheApplication.Current.Language = lang;
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            this.LanguageChooseBar.DataBind();
            if (this.LanguageChooseBar.SelectedItem == null)
            {
                this.LanguageChooseBar.SelectedValue = this.Application.Language;
            }

            if (this.Application.ApplicationUser != null)
            {
                this.WelcomePartLabel.Text = String.Format("Welcome {0}!", this.Application.ApplicationUser.UserName);
                this.LoginHead.Visible = false;
                this.LogoutHead.Visible = true;
            }
            else
            {
                this.WelcomePartLabel.Text = "";
                this.LoginHead.Visible = true;
                this.LogoutHead.Visible = false;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }

}
